package com.avic.rong.adapter.show;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.avic.rong.R;
import com.avic.rong.activity.ArticleDetailActivity;
import com.avic.rong.bean.show_bean.ShowBean;
import com.avic.rong.bean.show_bean.TypeBean;

import java.util.List;

/**
 * Created by TSJ-2018-0492 on 2019/8/9.
 */

public class BigRecommecdAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private LayoutInflater inflater;
    private List<ShowBean> bean;
    private Context context;
    private int TYPE_1 = 1, TYPE_2 = 2, TYPE_0 = 0, TYPE_3 = 3, TYPE_4 = 4, TYPE_5 = 5, TYPE_6 = 6, TYPE_7 = 7, TYPE_8 = 8;
    private DividerItemDecoration divider;


    public BigRecommecdAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setBean(List<ShowBean> bean) {
        this.bean = bean;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view;
        if (i == TYPE_0) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        } else if (i == TYPE_2) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        } else if (i == TYPE_3) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        } else if (i == TYPE_5) {
            view = inflater.inflate(R.layout.roofplacement_ment, viewGroup, false);
            return new BigRecommecdViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        BigRecommecdViewHolder holder = (BigRecommecdViewHolder) viewHolder;
        int itemViewType = getItemViewType(i);
        if (bean != null) {
            if (bean.get(i) != null) {
                if (bean.get(i).getType() != null) {
                    switch (itemViewType) {
                        case 0:
                            List<TypeBean> data = bean.get(i).getData();
                            RecommendAdapter followAdapter = new RecommendAdapter(context);
                            followAdapter.setData(data);
                            holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
                            holder.roofplacement_rec.setAdapter(followAdapter);
                            break;
                        case 2:
                            List<TypeBean> data1 = bean.get(i).getData();
                            TypeTwoAdapter followAdapter1 = new TypeTwoAdapter(context);
                            followAdapter1.setData(data1);
                            holder.roofplacement_rec.setLayoutManager(new LinearLayoutManager(context));
                            holder.roofplacement_rec.setAdapter(followAdapter1);
                            break;
                        case 3:
                            List<TypeBean> data2 = bean.get(i).getData();
                            TypethreeAdapter followAdapter2 = new TypethreeAdapter(context);
                            followAdapter2.setData(data2);
                            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
                            linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                            holder.roofplacement_rec.setLayoutManager(linearLayoutManager);
                            holder.roofplacement_rec.setAdapter(followAdapter2);
                            break;
//                        case 5:
//                            List<TypeBean> wendalist = bean.get(i).getData();
//                            LinearLayoutManager linearLayoutManagerwenda = new LinearLayoutManager(context);
//                            holder.roofplacement_rec.setLayoutManager(linearLayoutManagerwenda);
////                            holder.roofplacement_rec.setAdapter();
//                            break;
                        default:
                            return;
                    }
                }
            }
        } else {
            Toast.makeText(context, "数据空", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public int getItemCount() {

        if (bean != null) {
            return bean.size();
        }
        return 0;
    }

    @Override
    public int getItemViewType(int position) {
        if (bean != null) {
            if (bean.get(position) != null) {
                if (bean.get(position).getType() != null) {
                    String type = bean.get(position).getType();
                    int i1 = Integer.parseInt(type);
                    switch (i1) {
                        case 2:
                            return TYPE_2;
                        case 1:
                            return TYPE_0;
                        case 3:
                            return TYPE_3;
                        case 5:
                            return TYPE_5;
                    }
                }
            }
        }

        return super.getItemViewType(position);
    }
}
